package com.ibiaoke.system.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.system.entity.TopicPage;
import com.ibiaoke.system.entity.TopicPageExample;
import com.ibiaoke.system.mapper.TopicPageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TopicPageDao extends BaseDao {

    @Autowired
    private TopicPageMapper topicPageMapper;

    @Override
    public Object getMapper() {
        return topicPageMapper;
    }

    public List<TopicPage> listTopicPage(Integer position,Integer showStatus, Page page) {
        TopicPageExample example = new TopicPageExample();
        TopicPageExample.Criteria criteria = example.createCriteria().andDelStatusEqualTo(CommonConsts.NO);
        if(position!=null){
            criteria.andPositionEqualTo(position);
        }
        if(showStatus!=null){
            criteria.andShowStatusEqualTo(showStatus);
        }
        if(page!=null) {
            page.setTotalCount(countByExample(example));
            example.setLimitStart(page.limitStart());
            example.setLimitEnd(page.limitEnd());
        }
        example.setOrderByClause("sort");
        return selectByExample(example);
    }
}
